<?php
namespace app\admin\controller;

use app\admin\controller\AdminBaseController;
use think\Cache;
use think\Db;

/**
 * 广告管理
 * Class System
 */
class AdsController extends BaseController {
	 

	public function index(){
		$list=db("ads")->paginate(2);
		$this->assign('list',$list);
		return $this->fetch();
	}
	public function add_ads(){
		if($_POST){
			$data=get_query()['query'];
			$data['add_time']=now_time();
			$res=db('ads')->insert($data);
			if($res){
				 $this->success('添加成功',url("index"));
			}else{
				 $this->success('添加失败');
			}
		}
		return $this->fetch();
	}
	public function edit_ads($id){
		if($_POST){
			$data=get_query()['query'];;
            $data['update_time']=now_time();
			if(db('ads')->update($data)){
				 $this->success('更新成功',url("index"));
			}else{
				 $this->success('更新失败');
			}
		}
		$this->assign('ads',db('ads')->find($id));
		return $this->fetch();
	}
}
